export const prerender = false; import type { APIRoute } from "astro"; import { desc, eq } from "drizzle-orm"; import { createDb } from "@/db"; import { comments, events, profiles } from "@/db/schema"; export const GET: APIRoute = async ({ params, locals }) => { const runtime = locals.runtime as { env: { DATABASE_URL: string } }; const db = createDb(runtime.env.DATABASE_URL); const slug = params.slug; if (!slug) { return Response.json({ error: "Missing slug" }, { status: 400 }); } const [event] = await db .select({ id: events.id }) .from(events) .where(eq(events.slug, slug)); if (!event) { return Response.json({ error: "Event not found" }, { status: 404 }); } const rows = await db .select({ id: comments.id, parentId: comments.parentId, body: comments.body, depth: comments.depth, score: comments.score, createdAt: comments.createdAt, username: profiles.username, name: profiles.name, }) .from(comments) .innerJoin(profiles, eq(comments.profileId, profiles.id)) .where(eq(comments.eventId, event.id)) .orderBy(desc(comments.score), desc(comments.createdAt)); return Response.json(rows, { headers: { "Cache-Control": "public, s-maxage=10" }, }); };